<?php

namespace Admin\Models\crm;

use Admin\Models\BaseModel;

class XhcustInfo extends BaseModel
{

    /**
     *
     * @var integer
     * @Primary
     * @Identity
     * @Column(type="integer", length=11, nullable=false)
     */
    public $iCUId;


    /**
     *
     * @var string
     * @Column(type="string", nullable=true)
     */
    public $tCoopDate;

    /**
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    public $iMarketId;

    /**
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    public $iOperateId;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    public $iSchoolId;

    public $iGroupId;
    /**
     *
     * @var string
     * @Column(type="string", length=100, nullable=true)
     */
    public $sSchoolName;

    /**
     *
     * @var integer
     * @Column(type="integer", length=1, nullable=true)
     */
    public $bAgree;
    public $bCoop;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    public $iType;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    public $iLevel;

    /**
     *
     * @var string
     * @Column(type="string", length=50, nullable=true)
     */
    public $sIntroName;

    /**
     *
     * @var string
     * @Column(type="string", length=50, nullable=true)
     */
    public $sChargeName;


    public $sMarketName;
    public $sOperationName;

    /**
     *
     * @var string
     * @Column(type="string", length=50, nullable=true)
     */
    public $sChargePhone;

    /**
     *
     * @var integer
     * @Column(type="integer", length=1, nullable=true)
     */
    public $bWelfare;




    /**
     *
     * @var string
     * @Column(type="string", length=50, nullable=true)
     */
    public $sProvinceName;

    /**
     *
     * @var string
     * @Column(type="string", length=50, nullable=true)
     */
    public $sCityName;

    /**
     *
     * @var string
     * @Column(type="string", length=50, nullable=true)
     */
    public $sCountyName;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    public $sDetailedAddress;

    /**
     *
     * @var string
     * @Column(type="string", nullable=true)
     */
    public $tSchoolDate;

    public $mHistoryManage;

    /**
     *
     * @var integer
     * @Column(type="integer", length=1, nullable=true)
     */
    public $bDelete;

    /**
     *
     * @var string
     * @Column(type="string", nullable=true)
     */
    public $tCreateDate;

    /**
     *
     * @var integer
     * @Column(type="integer", length=20, nullable=true)
     */
    public $iCreateUserId;

    /**
     *
     * @var string
     * @Column(type="string", nullable=true)
     */
    public $tLastModifyDate;

    /**
     *
     * @var integer
     * @Column(type="integer", length=20, nullable=true)
     */
    public $iLastModifyUserId;


    public $iAidsLevel;

    /**
     * 历史创建人
     *
     * @var string
     *
     * create by xjq 20180710
     */
    public $mHistoryCreator;

    /**
     * 学段 （1 小学 2 初中 3 高中）
     *
     * @var integer
     *
     * create by dale 20180830
     */
    public $iStage;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
//        $this->setSchema("customer");
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHCust_Info';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhcustInfo[]|XhcustInfo
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhcustInfo
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     *  根据id数组获得  学校姓名数组
     *
     * @param $ids
     * @return array
     *
     */
    public static function findNameArrayByIds($ids){
        if (!$ids) {
            return [];
        }
        $objs = self::find([
            'columns' => 'iCUId,sSchoolName',
            'conditions' => 'iCUId in ({ids:array})',
            'bind' => ['ids' => $ids]
        ]);
        if (!$objs) {
            return [];
        }
        $arrayName = $objs->toArray();
        $arrayName = array_column($arrayName, 'sSchoolName', 'iCUId');

        return $arrayName;
    }

    public function afterFetch()
    {
        $this->mHistoryCreator = $this->mHistoryCreator ? unserialize($this->mHistoryCreator) : [];
    }


    public function beforeSave()
    {
        $this->mHistoryCreator = serialize($this->mHistoryCreator);
    }

}
